<template>
    <div>
        <base-list ref="cargoName" :condition="condition" :datas.sync="cargoName" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="100px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="货类名称">
                            <auto-cargo searchName="cargoTypeName" @select="v=>condition['search_LIKE_cargoTypeName']=v"></auto-cargo>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="货名代码">
                            <auto-cargo searchName="cargoCode" @select="v=>condition['search_EQ_cargoCode']=v" type="name"></auto-cargo>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="货名">
                            <auto-cargo searchName="cargoName" @select="v=>condition['search_LIKE_cargoName']=v" type="name"></auto-cargo>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-button type="primary" icon="el-icon-search" @click="loadData" class="ml-100">查 询</el-button>
                        <el-button formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WJOB_BASEMGR_MACHINE:ADD')">
                            新增
                        </el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-table slot="list" :data="cargoName" border stripe max-height="550">
                <el-table-column prop="cargoTypeName" label="货类名称"  min-width="130"></el-table-column>
                <el-table-column prop="cargoCode" label="货名代码"  min-width="130"></el-table-column>
                <el-table-column prop="cargoName" label="货名"  min-width="130"></el-table-column>
                <el-table-column prop="remark" label="备注"  min-width="200"></el-table-column>
                <el-table-column prop="lastModifiedBy" label="最后修改人"  min-width="200"></el-table-column>
                <el-table-column prop="lastModifiedDateTime" label="最后修改时间"  min-width="200"></el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)" v-if="power('WJOB_BASEMGR_MACHINE:UPD')">
                            编辑
                        </el-button>
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row)" v-if="power('WJOB_BASEMGR_MACHINE:DEL')">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <cargo-name-form ref="cargoNameForm" @load="loadData"></cargo-name-form>
    </div>
</template>

<script>
    import { deleteCargoName, getCargoNameList } from "@/api/baseResource/baseResource"
    import autoCargo from '@/components/autocomplete/autoCargo'
    import cargoNameForm from './cargoNameForm'

    export default {
        name: "cargoName",
        components: {
            cargoNameForm,
            autoCargo
        },
        data() {
            return {
                condition: {}, // 查询条件
                cargoName: [], // table数组
                pageSearch: getCargoNameList, // 分页查询api接口
                id: ''
            }
        },
        mounted() {
            this.$nextTick(() => {
                this.loadData()
            })
        },
        methods: {
            loadData() {
                this.$refs.cargoName.loadData()
            },
            handleDialogFormOpen(bool, item) {
                if (bool) {
                    let form = JSON.parse(JSON.stringify(item))
                    this.$refs.cargoNameForm.form = form
                    this.$refs.cargoNameForm.isEdit = true
                    this.$refs.cargoNameForm.dialogForm = true
                } else {
                    this.$refs.cargoNameForm.dialogForm = true
                }
            },
            handleRemove(item) {
                this.$confirm(`是否删除该数据?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteCargoName(item.id).then(res => {
                        this.$message({
                            type: 'success',
                            message: `删除成功!`
                        });
                        this.loadData()
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
            }
        },
    }

</script>

<style scoped>


</style>
